package kotlinquanweizhinan.chapt03条件语句.range
fun main(){
    val name = "Madrigal"
    val healthPoints = 80
    val isBlessed = true //是否走运
    val isImmortal = false //记录玩家是否永生

    //Aura 根据条件是否显示光环
    //if(isBlessed && healthPoints > 50 || isImmortal){
    val auraVisible = isBlessed && healthPoints > 50  || isImmortal //在变量定义时使用逻辑运行符

//    if(auraVisible){
//        println("GREEN")
//    }else{
//        println("NONE")
//    }

    //使用条件表达式优化光环判断代码
    val auraColor = if(auraVisible) "GREEN" else "NONE"
    println(auraColor)

//    if(healthPoints == 100){
//        println(name + " is in excellent conditioin!")
//    }else if(healthPoints >=90){
//        println(name + " has a few scrateches.")
//    }else if(healthPoints >=75){
//        println(name + " has some minor wounds.")
//    }
//    else if(healthPoints >=15){
//        println(name + " looks pretty hurt.")
//    }else{
//        println(name + " is in awful condition!")
//    }

    //使用条件表达式将健康状况赋值给某个变量。
//    val healthStatus = if(healthPoints == 100){
//        "is in excellent conditioin!"
//    }else if(healthPoints >=90){
//        "has a few scrateches."
//    }else if(healthPoints >=75){
//        " has some minor wounds."
//    }else if(healthPoints >=15){
//        " looks pretty hurt."
//    }else{
//        "is in awful condition!"
//    }

    //使用range重构healthStatus求值
        val healthStatus = if(healthPoints == 100){
        "is in excellent conditioin!"
    }else if(healthPoints in 90 ..99){
        "has a few scrateches."
    }else if(healthPoints in 75..89){
        if(isBlessed){
            "has some minor woonds but is healing quite quickly!"
        }else{
            " has some minor wounds."
        }
    }else if(healthPoints in 15..74){
        " looks pretty hurt."
    }else{
        "is in awful condition!"
    }

    //Player status
    println(name + healthStatus)
}